package com.dqyt.khjc.controller;

import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ModelController {

    @Autowired
    private ModelService modelService;


    /**
     * 分页查询型号规格
     * @param request
     * @param page
     * @param size
     * @param name
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/getModelListPage", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getZzcsListPage(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "name", required = false, defaultValue = "") String name,
                                     @RequestParam(name = "parentid", required = false, defaultValue = "0") long parentid,
                                     @RequestParam(name = "mtype", required = false, defaultValue = "0") String mtype
    ){
        ResultMsg resultMsg = modelService.getModelListPage(request,page,size,name,parentid,mtype);
        return resultMsg;
    }


    /**
     * 新增型号规格
     * @param request
     * @param name
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/addModel", method = {RequestMethod.POST})
    public  ResultMsg addModel(HttpServletRequest request,String name,long parentid,int mtype){
        ResultMsg resultMsg = modelService.addModel(request,name,parentid,mtype);
        return resultMsg;
    }

    /**
     * 删除型号规格
     * @param request
     * @param modelId
     * @return
     */
    @RequestMapping(value = "/api/delModel", method = {RequestMethod.POST})
    public  ResultMsg delModel(HttpServletRequest request,long modelId){
        ResultMsg resultMsg = modelService.delModel(request,modelId);
        return resultMsg;
    }

    /**
     * 修改型号规格
     * @param request
     * @param modelId
     * @param name
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/updateModel", method = {RequestMethod.POST})
    public  ResultMsg updateModel(HttpServletRequest request,long modelId,String name,long parentid,String mtype){
        ResultMsg resultMsg = modelService.updateModel(request,modelId,name,parentid,mtype);
        return resultMsg;
    }


    /**
     * 查询某个制造厂商下面的所有型号
     * @param request
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/getModelByPid", method = {RequestMethod.POST})
    public  ResultMsg getModelByPid(HttpServletRequest request,long parentid){
        ResultMsg resultMsg = modelService.getModelByPid(request,parentid);
        return resultMsg;
    }



    /**
     * 查询某个制造厂商下面的所有型号
     * @param request
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/getModelHxqByPid", method = {RequestMethod.POST})
    public  ResultMsg getModelHxqByPid(HttpServletRequest request,long parentid){
        ResultMsg resultMsg = modelService.getModelHxqByPid(request,parentid);
        return resultMsg;
    }



    /**
     * 查询某个制造厂商下面的所有型号
     * @param request
     * @param parentid
     * @return
     */
    @RequestMapping(value = "/api/getModelFhqpByPid", method = {RequestMethod.POST})
    public  ResultMsg getModelFhqpByPid(HttpServletRequest request,long parentid){
        ResultMsg resultMsg = modelService.getModelFhqpByPid(request,parentid);
        return resultMsg;
    }



}
